package cn.kgc.springmvc.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/2/29
 * @description
 */
@RestController
@RequestMapping("student")
public class StudentController {

    @RequestMapping("delete")
    @ResponseBody
    public Map<String,Object> deleteUser(Integer id) {

        if (id<0){
            throw  new RuntimeException("参数异常");
        }
        HashMap<String, Object> result = new HashMap<String, Object>();
        result.put("code",0);
        result.put("message","删除成功"+id);
        return result ;
    }


    // 自定义方法  用于处理当前类中的异常
    // @ExceptionHandler(Exception.class)
    // @ResponseBody
    // public  Map<String,Object>  exceptionHandler(Exception e){
    //     System.out.println(e.getMessage());
    //     e.printStackTrace();
    //     HashMap<String, Object> result = new HashMap<String, Object>();
    //     result.put("code",500);
    //     result.put("message","服务器繁忙,请稍后再试");
    //
    //     return result;
    // }
}
